package com.test30_IO流;

import org.junit.Test;

import java.io.*;

/**
 * 转换流
 * InputStreamReader
 * OutputStreamWriter
 * 转换流全部都是字符流的子类，主要功能就是将字节流转为字符流
 */
public class Demo06_InputStreamReader {

    /**
     * OutputStreamWriter
     */
    @Test
    public void test1() throws Exception {
        File file = new File("F:" + File.separator + "muyan" + File.separator + "vip" + File.separator + "yootk.txt");
        if (!file.getParentFile().exists()) {
            file.getParentFile().mkdirs();
        }
        Writer out = new OutputStreamWriter(new FileOutputStream(file));
        out.write("www.yootk.com");
        out.close();
    }

    /**
     * InputStreamReader
     */
    @Test
    public void test2() throws Exception {
        File file = new File("F:" + File.separator + "muyan" + File.separator + "vip" + File.separator + "yootk.txt");
        if (file.exists()) {
            Reader in = new InputStreamReader(new FileInputStream(file));
            char[] data = new char[1024];
            int len = in.read(data);
            System.out.println(new String(data, 0, len));
            in.close();
        }
    }
}
